<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/11/20
 * Time: 16:48
 */
namespace common\sources\write\taobao;

use common\sources\write\taobao\ITaoBaoAccess;
use common\models\craftsman\TaoBao;
use Yii;

class TaoBaoAccess implements ITaoBaoAccess
{
    public function addTaoBao($param)
    {
        return Yii::$app->db->createCommand()->insert('taobao', [
            'tbname' =>  $param['tbname'],
            'buy_id' => $param['buy_id'],
            'sex' => $param['sex'],
            'zfbname'=>$param['zfbname'],
            'zfbage' => $param['zfbage'],
            'takename' => $param['takename'],
            'takephone' => $param['takephone'],
            'pro_name' =>$param['pro_name'],
            'pro_code' => $param['pro_code'],
            'city_name' => $param['city_name'],
            'city_code' => $param['city_code'],
            'area_name' => $param['area_name'],
            'area_code' => $param['area_code'],
            'addr' => $param['addr'],
            'zfbname_img' => $param['zfbname_img'],
            'ip_img' => $param['ip_img'],
            'tqz_img' => $param['tqz_img'],
            'addr' => $param['addr'],
            'zfbhb_img' => $param['zfbhb_img'],
            'zfbname_img' => $param['zfbname_img'],
            "takeaddr" => $param['takeaddr'],
            'create_time' => time(),
            'audit_status' => 1,
        ])->execute();
    }

    public function modifyTaoBao($data)
    {
        $sql = 'UPDATE ' . TaoBao::tableName() . ' SET tbname = :tbname,sex = :sex,zfbname = :zfbname,zfbage = :zfbage,takename = :takename,
        takephone = :takephone,pro_name = :pro_name,pro_code = :pro_code,city_name = :city_name,city_code = :city_code,area_name = :area_name,
        area_code = :area_code,addr = :addr,zfbname_img = :zfbname_img,ip_img = :ip_img,tqz_img = :tqz_img,takeaddr = :takeaddr,zfbhb_img = :zfbhb_img,audit_status = :audit_status,
        update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':tbname' => $data['tbname'],
                ':sex' => $data['sex'],
                ':zfbname' => $data['zfbname'],
                ':zfbage' => $data['zfbage'],
                ':takename' => $data['takename'],
                ':takephone' => $data['takephone'],
                ':pro_name' => $data['pro_name'],
                ':pro_code' => $data['pro_code'],
                ':city_name' => $data['city_name'],
                ':city_code' => $data['city_code'],
                ':area_name' => $data['area_name'],
                ':area_code' => $data['area_code'],
                ':addr' => $data['addr'],
                ':zfbname_img' => $data['zfbname_img'],
                ':ip_img' => $data['ip_img'],
                ':tqz_img' => $data['tqz_img'],
                ':takeaddr' => $data['takeaddr'],
                ':zfbhb_img' => $data['zfbhb_img'],
                ':audit_status' => $data['audit_status'],
                ':update_time' => time(),
                ':id' => $data['tb_id']
            ])->execute();
    }

    public function modifyReceiveStatus($data)
    {
        $sql = 'UPDATE ' . TaoBao::tableName() . ' SET is_receive_task = :is_receive_task,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':is_receive_task' => $data['is_receive_task'],
                ':update_time' => time(),
                ':id' => $data['tb_id']
            ])->execute();
    }
}